<!--
报告管理-上传录制视频
 add by yyp 2020-03-14
-->
<template lang="pug">
  kalix-dialog.user-add(bizKey="Report" ref="kalixBizDialog"
  v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" )
    div.el-form(slot="dialogFormSlot" style=" width:60%;margin:auto;")
      el-form-item.short(label="录播视频" prop="videoUrl" v-bind:label-width="labelWidth" v-bind:rules="rules.videoUrl")
        kalix-clansman-upload-video(:action="action1" v-on:filePath="getFilePathVideo" fileType="video" :limit="1"  :fileList="fileList" tipText="只能上传视频文件")
</template>

<script type="text/ecmascript-6">
  import FormModel from './model'
  import {ReportURL, ClassURL, HospitalURL, FileURL} from '../../config.toml'
  import KalixClansmanUpload from '../../../../../components/fileUpload/upload'
  import KalixClansmanUploadVideo from '../../../../../components/fileUpload/uploadvideo'
  import {baseURL, NodeURL} from '../../../../../config/global.toml'
  import KalixSelect from '../../../../../components/corelib/components/common/baseSelect'
  import VuePlayer from '../../../../../components/corelib/components/common/vue-player.vue'

  export default {
    name: 'reportEdit',
    components: {
      KalixSelect,
      KalixClansmanUpload,
      VuePlayer,
      KalixClansmanUploadVideo
    },
    data() {
      return {
        action: baseURL + '/camel/rest/upload',
        action1: NodeURL,
        formModel: Object.assign({}, FormModel),
        rules: {
          videoUrl: [{required: true, message: '请上传示范课视频', trigger: 'blur'}]
        },
        targetURL: ReportURL,
        labelWidth: '110px',
        fileList: [],
        filePathArr: [],
        videoType: [],
        videoUrl: null,
        filePathArrVideo: []
      }
    },
    mounted() {
      this.getClassType()
      this.getHospital()
      this.getFile()
    },
    methods: {
      getClassType() {
        this.axios.request({
          method: 'GET',
          url: ClassURL
        }).then(res => {
          this.claName = res.data.data
        })
      },
      getHospital() {
        this.axios.request({
          method: 'GET',
          url: HospitalURL
        }).then(res => {
          this.HoName = res.data.data
        })
      },
      getFile() {
        this.axios.request({
          method: 'GET',
          url: FileURL
        }).then(res => {
          this.fileData = res.data.data
        })
      },
      getFilePathVideo(filePath, fileName) { // 视频上传路径
        this.formModel.videoUrl = 'https://xsdmkj.cn/node/' + fileName
      },
      ImgDel(curriculumFile) {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          let arrImg = this.formModel.curriculumFile.split(',')
          let idx = arrImg.indexOf(curriculumFile)
          arrImg.splice(idx, 1)
          this.formModel.curriculumFile = arrImg.join(',')
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      deleteVideo() {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.videoUrl = null
          this.formModel.videoUrl = ''
          console.log('123123123', this.formModel.videoUrl)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        }).catch(() => {
        })
      },
      init(dialogOption) {
        console.log('---------dialogOption------------', dialogOption)
        if (this.formModel.videoUrl !== null && this.formModel.videoUrl !== '') {
          this.fileList = [
            {
              name: '',
              url: ''
            }
          ]
          let str1 = this.formModel.videoUrl.lastIndexOf('/')
          this.filePathArrVideo.push(this.formModel.videoUrl)
          this.fileList[0].url = this.formModel.videoUrl
          this.fileList[0].name = this.formModel.videoUrl.substring(str1 + 1, this.formModel.videoUrl.length)
        }
      },
      submitBefore(baseDialog, callBack) {
        let filePath = ''
        if (this.filePathArr.length > 0) {
          this.filePathArr.forEach(e => {
            filePath += e + ','
          })
          filePath = filePath.substr(0, filePath.length - 1)
        }
        baseDialog.formModel.curriculumFile = filePath
        let filePath2 = ''
        if (this.filePathArr2.length > 0) {
          this.filePathArr2.forEach(e => {
            filePath2 += e + ','
          })
          filePath2 = filePath2.substr(0, filePath2.length - 1)
        }
        baseDialog.formModel.curriculumFileTwo = filePath2
        let filePath3 = ''
        if (this.filePathArr3.length > 0) {
          this.filePathArr3.forEach(e => {
            filePath3 += e + ','
          })
          filePath3 = filePath3.substr(0, filePath3.length - 1)
        }
        baseDialog.formModel.curriculumFileThree = filePath3
        let filePath4 = ''
        if (this.filePathArr4.length > 0) {
          this.filePathArr4.forEach(e => {
            filePath4 += e + ','
          })
          filePath4 = filePath4.substr(0, filePath4.length - 1)
        }
        baseDialog.formModel.curriculumFileFour = filePath4
        let filePath5 = ''
        if (this.filePathArr5.length > 0) {
          this.filePathArr5.forEach(e => {
            filePath5 += e + ','
          })
          filePath5 = filePath5.substr(0, filePath5.length - 1)
        }
        baseDialog.formModel.curriculumFileFive = filePath5
        callBack()
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
  .el-form
    width 50%
    margin auto
    .radio
      margin-left 150px
      margin-bottom 20px
      .el-radio
        color: #3465cb
        font-weight: bold
        font-size: 14px

  .img-margin
    margin-left 150px
</style>
